package com.ruoyi.system.service.impl;


import com.ruoyi.common.core.domain.entity.InstitutionMoment;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.system.mapper.InstitutionMomentMapper;
import com.ruoyi.system.service.IInstitutionMomentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 机构动态信息 业务层处理
 *
 * @author ruoyi
 */
@Service
public class IInstitutionMomentServiceImpl implements IInstitutionMomentService {

    @Autowired
    private InstitutionMomentMapper institutionMomentMapper;

    /**
     * 查询当前机构所有动态信息
     *
     * @return 机构动态信息和集合
     */
    @Override
    public List<InstitutionMoment> selectAllMoment(InstitutionMoment institutionMoment) {
        System.out.println(institutionMoment.toString());
        return institutionMomentMapper.selectAllMoment(institutionMoment);
    }

    /**
     * 根据机构动态id查询动态信息
     *
     * @param mId 机构动态信息
     * @return 机构动态信息
     */
    @Override
    public InstitutionMoment selectMomentById(Long mId) {
        return institutionMomentMapper.selectMomentById(mId);
    }

    /**
     * 添加机构动态信息
     *
     * @param institutionMoment 机构动态信息
     * @return boolean (true 添加成功，false 添加失败)
     */
    @Override
    public boolean insertMoment(InstitutionMoment institutionMoment) {
        return institutionMomentMapper.insertMoment(institutionMoment) == 1;
    }

    /**
     * 修改机构动态信息
     *
     * @param institutionMoment 修改后的机构动态信息
     * @return boolean (true 修改成功，false 修改失败)
     */
    @Override
    public boolean updateMoment(InstitutionMoment institutionMoment) {
        boolean b = institutionMomentMapper.updateMoment(institutionMoment);
        System.out.println("institutionMomentMapper.updateMoment(institutionMoment);"+b);
        return b;

    }

    /**
     * 删除机构动态信息
     *
     * @param mId 机构动态id
     * @return boolean (true 删除成功，false 删除失败)
     */
    @Override
    public boolean deleteMomentById(Long mId) {
        return institutionMomentMapper.deleteMomentById(mId) == 1;
    }

    /**
     * 删除机构动态信息信息
     *
     * @param mIds 机构动态信息ID
     * @return boolean (true 删除成功，false 删除失败)
     */
    @Override
    public boolean deleteMomentByIds(String mIds) {

        //字符串转换为字符数组
        String[] midArray = Convert.toStrArray(mIds);

        //所删除动态条数是否与勾选数目相同
        return institutionMomentMapper.deleteMomentByIds(midArray) == midArray.length;
    }

    /**
     * 查询机构id
     *
     * @param userId 用户id
     * @return 机构id
     */
    @Override
    public int selectInstitutionIdByUserId(Long userId) {
        return institutionMomentMapper.selectInstitutionIdByUserId(userId);
    }


}
